#include"process.h"
#include<string.h>
#include<unistd.h>

#define LENGTH 101
#define LABLE '#'

//version2
void Flushprocess(double size,double current)
{
	char bar[101];
	memset(bar,0,sizeof(bar));
	const char *sym = "|/-\\";
	static int index = 0;
	int len = strlen(sym);
	double rate = current/size*100;
	int cnt = (int)rate;
	
	for(int i=0;i<cnt;i++)
		bar[i] = LABLE;
	
	index%=len;
	printf("[%-100s][%.1f%%][%c]\r",bar,rate,sym[index]);
	index++;
	fflush(stdout);
	
	
}


//version1
void process()
{
	char bar[LENGTH];
	const char *symb = "|-/\\";

	memset(bar,'\0',sizeof(bar));
	int cnt = 0;
	int s_symb = strlen(symb);

	while(cnt<=100)
	{
		printf("[%-100s][%d%%][%c]\r",bar,cnt,symb[cnt%s_symb]);
		fflush(stdout);
		bar[cnt] = LABLE;
		cnt++;
		usleep(10000);
	}
	printf("\n");
}
